package com.admin.business.venusOrganizeBanner;

import com.tiangong.framework.annotation.OpenApi;
import com.tiangong.framework.bo.CDO;
import com.tiangong.framework.bo.Return;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description: 官网banner信息表
 * @create: 2022-07-08 19:04:49
 **/
@Service("venusOrganizeBanner")
@Slf4j
public class VenusOrganizeBannerService{

    @Resource
    VenusOrganizeBannerDao venusOrganizeBannerDao;

    /**
     * 添加官网banner信息表,获取banner_id数据
     *
     * @param cdoRequest - banner_id:
     *                   - banner_org_id:公司id
     *                   - banner_template_id:模板Id
     *                   - banner_type:baner类型
     *                   - banner_pictures:图片集
     *                   - banner_url:banner路径连接
     *                   - banner_sort:banner排序
     *                   - banner_progress_num:进度条个数
     *                   - banner_progress_flag:进度条显隐
     * @return
     * @author ht
     * @create: 2022-07-08 19:04:49
     */
    @OpenApi
    public Return addVenusOrganizeBanner(CDO cdoRequest) {
        venusOrganizeBannerDao.addVenusOrganizeBanner(cdoRequest);
        CDO cdoResult = new CDO();
        if (cdoRequest.containsKey("banner_id")) {
            cdoResult.set("banner_id", cdoRequest.get("banner_id"));
        }
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据banner_id，更新官网banner信息表数据
     *
     * @param cdoRequest - banner_id:
     *                   - banner_org_id:公司id
     *                   - banner_template_id:模板Id
     *                   - banner_type:baner类型
     *                   - banner_pictures:图片集
     *                   - banner_url:banner路径连接
     *                   - banner_sort:banner排序
     *                   - banner_progress_num:进度条个数
     *                   - banner_progress_flag:进度条显隐
     * @return
     * @author ht
     * @create: 2022-07-08 19:04:49
     */
    @OpenApi
    public Return updateVenusOrganizeBannerById(CDO cdoRequest) {
        int affectedRows = venusOrganizeBannerDao.updateVenusOrganizeBannerById(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("affectedRows", affectedRows);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据banner_id，删除官网banner信息表数据
     *
     * @param cdoRequest - banner_id:
     * @return
     * @author ht
     * @create: 2022-07-08 19:04:49
     */
    @OpenApi
    public Return deleteVenusOrganizeBannerById(CDO cdoRequest){
        int affectedRows = venusOrganizeBannerDao.deleteVenusOrganizeBannerById(cdoRequest.getLong("banner_id"));
        CDO cdoResult = new CDO();
        cdoResult.set("affectedRows", affectedRows);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据条件，删除官网banner信息表数据
     *
     * @param cdoRequest - banner_org_id:公司id
     *                   - banner_template_id:模板Id
     *                   - banner_type:baner类型
     *                   - banner_sort:banner排序
     * @return
     * @author ht
     * @create: 2022-07-08 19:04:49
     */
    @OpenApi
    public Return deleteVenusOrganizeBanner(CDO cdoRequest) {
        int affectedRows = venusOrganizeBannerDao.deleteVenusOrganizeBanner(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("affectedRows", affectedRows);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据ID，获取官网banner信息表数据
     *
     * @param cdoRequest - banner_id:
     * @return
     * @author ht
     * @create: 2022-07-08 19:04:49
     */
    @OpenApi
    public Return getVenusOrganizeBannerById(CDO cdoRequest) {
        CDO cdoMapperResult = venusOrganizeBannerDao.getVenusOrganizeBannerById(cdoRequest.getLong("banner_id"));
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据混合条件，获取官网banner信息表数据
     *
     * @param cdoRequest - banner_id:
     *                   - banner_org_id:公司id
     *                   - banner_template_id:模板Id
     *                   - banner_type:baner类型
     *                   - banner_sort:banner排序
     * @return
     * @author ht
     * @create: 2022-07-08 19:04:49
     */
    @OpenApi
    public Return getVenusOrganizeBanner(CDO cdoRequest) {
        CDO cdoMapperResult = venusOrganizeBannerDao.getVenusOrganizeBanner(cdoRequest);
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据非空条件，获取官网banner信息表数据列表
     *
     * @param cdoRequest - banner_org_id:公司id
     *                   - banner_template_id:模板Id
     *                   - banner_type:baner类型
     *                   - banner_sort:banner排序
     * @return
     * @author ht
     * @create: 2022-07-08 19:04:49
     */
    @OpenApi
    public Return getVenusOrganizeBannerList(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.containsKey("pageIndex") ? cdoRequest.getInteger("pageIndex") : 0;
        int recordSize = cdoRequest.containsKey("recordSize") ? cdoRequest.getInteger("recordSize") : 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusOrganizeBannerDao.getVenusOrganizeBannerList(cdoRequest);
        boolean isEndPage = cdoMapperResultList.size() < recordSize;
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据混合条件，获取官网banner信息表数据列表
     *
     * @param cdoRequest - banner_id:
     *                   - banner_org_id:公司id
     *                   - banner_template_id:模板Id
     *                   - banner_type:baner类型
     *                   - banner_sort:banner排序
     * @return
     * @author ht
     * @create: 2022-07-08 19:04:49
     */
    @OpenApi
    public Return getVenusOrganizeBannerListByCondition(CDO cdoRequest) {
        int pageIndex = cdoRequest.containsKey("pageIndex") ? cdoRequest.getInteger("pageIndex") : 0;
        int recordSize = cdoRequest.containsKey("recordSize") ? cdoRequest.getInteger("recordSize") : 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusOrganizeBannerDao.getVenusOrganizeBannerListByCondition(cdoRequest);
        boolean isEndPage = cdoMapperResultList.size() < recordSize;
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
        return Return.valueOf(cdoResult);
    }
}
